import Vue from 'vue'
import VueRouter from 'vue-router'
import test from '../views/test.vue'
import home from '../views/home.vue'
import busInformation from '../components/busInformation.vue'
import hello from '../views/hello.vue'
import homeTest from '../components/homeTest.vue'
import login from '../login.vue'
import forget from '../forget.vue'
import sctterMap from '../components/sctterMap.vue'
import Testhello from '../components/Test.vue'
import routeInformation from '../components/routeInformation.vue'
import StaffLogin from '../Staff/Stafflogin.vue'
import StaffHome from '../Staff/StaffHome.vue'
import StaffHello from '../Staff/StaffHello.vue'
import StaffSec from '../Staff/StaffSec.vue'
import GaodeMap from '../components/GaodeMap.vue'
import SearchMap from '../components/SearchMap.vue'
import printTest from '../components/printTest.vue'
import driverPrint from '../components/driverPrint.vue'
import vedio from '../components/video.vue'
import helloLogin from '../views/login.vue'
import siteInformation from '../components/sitesInformation.vue'
import AddRotationMap from '../components/AddRotationMap.vue'
import updateContenxt from '../components/updateContenxt.vue'
import GetEmail from '../components/GetEmail.vue'
import activity from '../components/activity.vue'
import qiantai from '../components/qiantaiUser.vue'
import driverSa from '../components/DriverSalary.vue'
import PunishmentManagement from '../components/PunishmentManagement.vue'

Vue.use(VueRouter);

const routes = [
    // 登录页面
  {
    path: '/',
    name: 'login',
    component: login
  },
  {
    path:'/test',
    name:'test',
    component:test
  },
    //公交车公司使用的 后台页面
  {
    path:'/home',
    name:home,
    component:home,
    children:[
      {
        path:'/busInformation',
        name:busInformation,
        component:busInformation
      },
      {
        path:'/hello',
        name:hello,
        component:hello
      },
      {
        path:'/homeTest',
        name:homeTest,
        component:homeTest
      },
      {
        path:'/dataMap',
        name:sctterMap,
        component:sctterMap
      },
      {
        path:'/Testhello',
        name:Testhello,
        component:Testhello
      },
      {
        path:'/routeInformation',
        name:routeInformation,
        component:routeInformation
      },
      {
        path:'/sitesInformation',
        name:siteInformation,
        component:siteInformation
      },
      {
        path:'/addrotation',
        name:AddRotationMap,
        component:AddRotationMap
      },
      {
        path:'/updateContext',
        name:updateContenxt,
        component:updateContenxt
      },
      {
        path:'/getEmail',
        name:GetEmail,
        component:GetEmail
      },
      {
        path:'/activity',
        name:activity,
        component:activity
      },
      {
        path:'/qiantai',
        name:qiantai,
        component:qiantai
      },
      {
        path:'/driversa',
        name:driverSa,
        component:driverSa
      },
        {
            path:'/PunishmentManagement',
            name:PunishmentManagement,
            component:PunishmentManagement
        }
    ]
  },
    //忘记密码页面
  {
    path:'/forget',
    name:forget,
    component:forget
  },
    //公交车司机登录页面
  {
    path:'/StaffLogin',
    name:'StaffLogin',
    component:StaffLogin
  },
    //公交车司机管理页面
  {
    path:'/StaffHome',
    name:'StaffHome',
    component:StaffHome,
    children: [
      {
        path:'/StaffHello',
        name:'StaffHello',
        component:StaffHello
      },
        {
            path: '/StaffSec',
            name: 'StaffSec',
            component: StaffSec
        },
        {
            path:'/driverPrint',
            name:'driverPrint',
            component:driverPrint
        }
    ]
  },
    {
        path:'/Gaode',
        name:'GaodeMap',
        component:GaodeMap
    },
  {
    path:'/SearchMap',
    name:'SearchMap',
    component:SearchMap
  },
  {
    path:'/print',
    name:printTest,
    component:printTest
  },
  {
    path:'/vedio',
    name:vedio,
    component:vedio
  },
  {
    path:'/helloLogin',
    name:helloLogin,
    component:helloLogin
  }
]

const router = new VueRouter({
  routes
});

router.beforeEach((to,from,next)=>{
  if(to.path==='/helloLogin') return next();
  if(to.path==='/StaffLogin') return next();
  if(to.path==='/forget') return next();
  const tokenstr=window.sessionStorage.getItem("username");
  if(!tokenstr) return next('/helloLogin');
  if(tokenstr) return next();
});

export default router
